<template>
	<view>
		<navbar title="增加数据" :isbg="false" :autoBack="false" :opacity='1'>
			<view class="u-flex u-flex-y-center" slot='leftbtn'>
				<u-icon name="arrow-left" color="#1E1E1E" size="32rpx" @click="back"></u-icon>
				{{city}}
			</view>
			<image :class="issx?'spin-element':''" @click="getaddr" src="/static/data/addsx.png" slot='rightbtn' style="width: 37rpx;height: 37rpx;" mode=""></image>
		</navbar>
		<view class="con">
			<view class="box">
				<view class="box__item">
					<view class="box__item__label">
						客户名称:
					</view>
					<input type="text" class="box__item__inp" placeholder="请输入客户名称" v-model="form.name" />
				</view>
				<view class="box__item">
					<view class="box__item__label">
						成交金额(元):
					</view>
					<input type="number" class="box__item__inp" v-model="form.dedamount" placeholder="请输入成交金额" />
				</view>
				<view class="box__item">
					<view class="box__item__label">
						联系人:
					</view>
					<input type="text" class="box__item__inp" v-model="form.contract" placeholder="请输入联系人"/>
				</view>
				<view class="box__item">
					<view class="box__item__label">
						联系电话:
					</view>
					<input type="text" class="box__item__inp" v-model="form.phone" placeholder="请输入联系电话"/>
				</view>
				<view class="box__title">
					<view class="box__title__line">
						
					</view>
					地址
				</view>
				<view class="box__addr">
					<u--textarea v-model="form.address" autoHeight  border='none' placeholder="点击刷新按钮或手动输入地址" ></u--textarea>
					<!-- <input type="text" class="box__item__inp" v-model="form.address" placeholder="点击刷新按钮或手动输入地址" style="text-align: left;" /> -->
				</view>
				<view class="" style="padding:26rpx 20rpx 0 0;">
					<u--textarea v-model="form.remark" height='242rpx' border='none' placeholder="请输入备注信息" ></u--textarea>
					<u-button text="提交" @click="submit" :loading="btnloading" color="#2A51FA" :customStyle="{
						height:'95rpx',
						width:'638rpx',
						margin:0,
						fontSize:'30rpx',
						borderRadius:'20rpx'
					}"></u-button>
					<!-- <view class="btn" @click="submit">
						提交
					</view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import datagl from '@/api/_datagl.js'
	export default {
		data() {
			return {
				form: {
					name:'',
					dedamount:'',
					address:'',
					contract:'',
					phone:'',
					remark:''
				},
				city:'未知',
				issx:false,
				btnloading:false,
				key:'7HFBZ-Q7PCL-Q7FPK-MNB5G-HDYQ7-ZHFZJ'
			};
		},
		methods:{
			getaddr(){
				let _this=this
				_this.issx=true
				uni.showLoading({
					title:'正在获取地址'
				})
				uni.getLocation({
					geocode:true,
					type: 'gcj02',
					success: function (res) {
						uni.request({
							url:`https://apis.map.qq.com/ws/geocoder/v1/?location=${res.latitude},${res.longitude}&key=${_this.key}`,
							success(r) {
								console.log(r)
								_this.form.address=r.data.result.formatted_addresses.standard_address
								_this.city=r.data.result.address_component.city
								_this.issx=false
								uni.hideLoading()
							}
						})
						
					},
					fail(r) {
						_this.issx=false
						uni.hideLoading()
					},
					complete() {
						_this.issx=false
						uni.hideLoading()
					}
				});
			},
			async submit(){
				let {name,dedamount,contract,phone,address}=this.form
				if(!name){
					uni.$u.toast('请输入客户名称')
					return
				}
				if(!dedamount){
					uni.$u.toast('请输入成交金额')
					return
				}
				if(!contract){
					uni.$u.toast('请输入联系人')
					return
				}
				if(!phone){
					uni.$u.toast('请输入联系人电话')
					return
				}
				if(!address){
					uni.$u.toast('请输入地址')
					return
				}
				this.btnloading=true
				let res = await datagl.createCustomer(this.form)
				if(res.data.code==1){
					this.btnloading=false
					uni.$u.toast('添加成功')
					uni.navigateBack()
				}
			}
		},
		onLoad() {
			// #ifdef APP-VUE
			this.getaddr()
			// #endif
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F0F3F7;
	}

	.con {
		padding: 30rpx;
	}
	.box{
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		padding: 18rpx 4rpx 56rpx 30rpx;
		&__title{
			display: flex;
			align-items: center;
			font-family: PingFang-SC, PingFang-SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #6D6D6D;
			line-height: 28rpx;
			margin-bottom: 28rpx;
			margin-top: 36rpx;
			&__line{
				width: 6rpx;
				height: 27rpx;
				background: #2DA1E0;
				border-radius: 3rpx 3rpx 3rpx 3rpx;
				margin-right: 10rpx;
			}
		}
		&__item{
			height: 100rpx;
			border-bottom: 2rpx solid #F9F9F9;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-right: 25rpx;
			&__label{
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #6D6D6D;
				line-height: 38rpx;
			}
			&__inp{
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #020202;
				line-height: 38rpx;
				text-align: right;
				flex: 1;
			}
		}
		&__addr{
			font-family: PingFang-SC, PingFang-SC;
			font-weight: 500;
			font-size: 26rpx;
			color: #010101;
			line-height: 38rpx;
			padding-bottom: 24rpx;
			border-bottom: 2rpx solid #F9F9F9;
			::v-deep.u-textarea{
				background-color: #fff!important;
				border-radius: 20rpx!important;
				padding: 20rpx!important;
			}
		}
	}
	::v-deep.u-textarea{
		background-color: #F8F8F8!important;
		border-radius: 20rpx!important;
		padding: 20rpx!important;
	}
	.btn {
		width: 638rpx;
		height: 95rpx;
		background: #2A51FA;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: PingFang-SC, PingFang-SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 48rpx;
		margin-top: 39rpx;
	}
</style>